﻿using com.fmtx.IDal;
using com.fmtx.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using fmtx.Framework.DALFactory;

namespace website.Areas.Action.Controllers
{
    public class CollectController : BaseController
    {
        //
        // GET: /Action/Collect/
        private ICollect collect = DataAccess<ICollect>.GetObject();

        /// <summary>
        /// 收藏文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [IsLoginJson]
        public ActionResult DoCollectA(int id)
        {
            bool istrue = true;
            var msg = "";
            if (!collect.HasCollect(userInfo.Uid, Target.ARTICLE, id))
            {
                Collect model = new Collect();
                model.TagId = id;
                model.TagType = Target.ARTICLE;
                model.Uid = userInfo.Uid;
                collect.Add(model);
                msg = "收藏成功！";
            }
            else
            {
                istrue = false;
                msg = "收藏过了！";
            }
            return Json(new { success = istrue, msg = msg }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 收藏文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [IsLoginJson]
        public ActionResult DoCollectP(int id)
        {
            bool istrue = true;
            var msg = "";
            if (!collect.HasCollect(userInfo.Uid, Target.PICTRUE, id))
            {
                Collect model = new Collect();
                model.TagId = id;
                model.TagType = Target.PICTRUE;
                model.Uid = userInfo.Uid;
                collect.Add(model);
                msg = "收藏成功！";
            }
            else
            {
                istrue = false;
                msg = "收藏过了！";
            }
            return Json(new { success = istrue, msg = msg }, JsonRequestBehavior.AllowGet);
        }

    }
}
